#	$Id: epi.sys.mk 6 2006-08-07 19:49:01Z phrakt $
#	$OpenBSD: sys.mk,v 1.45 2005/03/07 00:06:00 deraadt Exp $
#	$NetBSD: sys.mk,v 1.27 1996/04/10 05:47:19 mycroft Exp $
#	@(#)sys.mk	5.11 (Berkeley) 3/13/91

OS!=		uname -s
OSREV!=		uname -r


.SUFFIXES: .out .a .ln .o .c .C .y .l .s .S .cl h .sh .m4

.LIBS:		.a

AR?=		ar
ARFLAGS?=	rl
RANLIB?=	ranlib
LORDER?=	lorder

AS?=		as
AFLAGS?=	${DEBUG}
COMPILE.s?=	${CC} ${AFLAGS} -c
LINK.s?=	${CC} ${AFLAGS} ${LDFLAGS}
COMPILE.S?=	${CC} ${AFLAGS} ${CPPFLAGS} -c
LINK.S?=	${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}

CC?=		cc

PIPE?=		-pipe
CFLAGS=		${PIPE}



COMPILE.c?=	${CC} ${CFLAGS} ${CPPFLAGS} -c
LINK.c?=	${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}

HOSTCC?=	cc

CPP?=		cpp
CPPFLAGS?=	

LEX?=		lex
LFLAGS?=
LEX.l?=		${LEX} ${LFLAGS}

LD?=		ld
LDFLAGS=

LINT?=		lint
LINTFLAGS?=	-chapbx

MAKE?=		make

SHELL?=		sh

RM?=		rm -f

YACC?=		yacc
YFLAGS?=	-d
YACC.y?=	${YACC} ${YFLAGS}

INSTALL?=	install
INSTALL_COPY?=	-c

CTAGS?=		/usr/bin/ctags


.if (${DEBUG:L} == "yes")
CFLAGS+=	${DEBUG} -DDEBUG=1
.else
CFLAGS+=	${OPTIM}
.endif

.if (${THREAD_SAFE:L} == "yes")
CFLAGS+=	-DTHREAD_SAFE=1
LDADD?=		-lpthread
.endif


# C
.c:
	${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
.c.o:
	${COMPILE.c} ${.IMPSRC}
.c.a:
	${COMPILE.c} ${.IMPSRC}
	${AR} ${ARFLAGS} $@ $*.o
	rm -f $*.o
.c.ln:
	${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}

# Assembly
.s:
	${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
.s.o:
	${COMPILE.s} ${.IMPSRC}
.s.a:
	${COMPILE.s} ${.IMPSRC}
	${AR} ${ARFLAGS} $@ $*.o
	rm -f $*.o
.S:
	${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
.S.o:
	${COMPILE.S} ${.IMPSRC}
.S.a:
	${COMPILE.S} ${.IMPSRC}
	${AR} ${ARFLAGS} $@ $*.o
	rm -f $*.o

# Lex
.l:
	${LEX.l} ${.IMPSRC}
	${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
	rm -f lex.yy.c
.l.c:
	${LEX.l} ${.IMPSRC}
	mv lex.yy.c ${.TARGET}
.l.o:
	${LEX.l} ${.IMPSRC}
	${COMPILE.c} -o ${.TARGET} lex.yy.c 
	rm -f lex.yy.c

# Yacc
.y:
	${YACC.y} ${.IMPSRC}
	${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
	rm -f y.tab.c
.y.c:
	${YACC.y} -p ${.IMPSRC:T:R} ${.IMPSRC}
	mv y.tab.c ${.TARGET}
.y.o:
	${YACC.y} -p ${.TARGET:R} ${.IMPSRC}
	${COMPILE.c} -o ${.TARGET} y.tab.c
	rm -f y.tab.c

# Shell
.sh:
	rm -f ${.TARGET}
	cp ${.IMPSRC} ${.TARGET}

.if (${OS} == "Linux")
.include "epi.linux.mk"
.endif
